<?php
namespace app\pay\controller\fumin;

use think\Controller;
use pay\fumin\RequestHandler;
use pay\fumin\Config;

class Test extends Controller
{
    private $reqHandler = null;
    private $cfg = null;
    
    public function request() {
        $this->reqHandler = new RequestHandler();
        $this->cfg = new Config();
    }

    public function index() {
        date_default_timezone_set('Asia/Shanghai');
        $outNo = 'CY' . date('YmdHis', time()) . rand(10, 99);
        $this->assign('timestamp', time());
        $this->assign('outNo', $outNo);
        return $this->fetch();
    }
    
   /*
    * 富民直接下单接口
    */
    public function order() {
        $this->request();
        $data = input('post.');
        $data['mchntId'] =  $this->cfg->C('mchntId'); // 必填项，商户号，由支付平台分配
        $data['payPowerId'] =  '51'; // 支付功能id
        $data['version'] = $this->cfg->C('version'); // 接口版本号
        $data['signature'] = $this->reqHandler->createSign($data); //创建签名
        dump($data);
        $encodeData = $this->reqHandler->rsaEncrypt($data['signature'], $data); //rsa加密
        dump($encodeData);
        $result = $this->reqHandler->curl($this->cfg->C('orderUrl'), $encodeData);
        return json_encode($result, 320);
    }
}

